/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.daten.konstant.sys;

import de.mnit.basis.daten.FilterText;
import de.mnit.basis.sys.Sys;

/**
 * @author Michael Nitsche
 *
 * http://www.osgi.org/Specifications/Reference
 *
 * Je Konstante eine Liste mit Möglichkeiten übergeben
 */
public enum SYSTEM {

	SONSTIGES		(SOFTWARE_HERSTELLER.SONSTIGER), //Platzhalter

	LINUX			(SOFTWARE_HERSTELLER.OPEN_SOURCE,	"Linux"),

	WINDOWS_95		(SOFTWARE_HERSTELLER.MICROSOFT, 	"Windows 95", "Win95"),
	WINDOWS_98		(SOFTWARE_HERSTELLER.MICROSOFT, 	"Windows 98", "Win98"),
	WINDOWS_NT		(SOFTWARE_HERSTELLER.MICROSOFT, 	"Windows NT", "WinNT"),
	WINDOWS_CE		(SOFTWARE_HERSTELLER.MICROSOFT, 	"Windows CE", "WinCE"),
	WINDOWS_2000	(SOFTWARE_HERSTELLER.MICROSOFT, 	"Windows 2000", "Win2000"),
	WINDOWS_XP		(SOFTWARE_HERSTELLER.MICROSOFT, 	"Windows XP", "WinXP"),
	WINDOWS_2003	(SOFTWARE_HERSTELLER.MICROSOFT, 	"Windows 2003", "Win2003", "Server 2003"),
	WINDOWS_VISTA	(SOFTWARE_HERSTELLER.MICROSOFT, 	"Windows Vista", "Vista", "WinVista"),
	WINDOWS_7		(SOFTWARE_HERSTELLER.MICROSOFT, 	"Windows 7", "Win7"),

	MAC_OS			(SOFTWARE_HERSTELLER.APPLE, 		"Mac OS"),
	MAC_OSX			(SOFTWARE_HERSTELLER.APPLE, 		"Mac OS X", "Darwin"),
	;


	private static SYSTEM aktuell=null;
	private final SOFTWARE_HERSTELLER herausgeber;
	private final String[] ident;


	private SYSTEM(SOFTWARE_HERSTELLER se, String... ident) {
		this.herausgeber=se;
		this.ident=ident;
	}


	public static SYSTEM gAktuell() {
		if(aktuell!=null)
			return aktuell;
		String system=iZuKurzKlein(Sys.gOsName());
		SYSTEM erg=null;
		for(SYSTEM s : SYSTEM.values()) {
			for(String str : s.ident)
				if(system.equals(iZuKurzKlein(str))) {
					erg=s;
					break;
				}
			if(erg!=null)
				break;
		}

		return erg==null ? SYSTEM.SONSTIGES : erg;
	}

	public SOFTWARE_HERSTELLER gHerausgeber() {
		return this.herausgeber;
	}

	public boolean istWindows() {
		return SYSTEM.gAktuell().herausgeber==SOFTWARE_HERSTELLER.MICROSOFT;
	}

	public boolean istLinux() {
		return SYSTEM.gAktuell()==SYSTEM.LINUX;
	}

	public boolean istMac() {
		return SYSTEM.gAktuell().herausgeber==SOFTWARE_HERSTELLER.APPLE;
	}

	//Wenn nötig und wirklich sinnvoll, dann als Konstruktorparameter!
//	public static final String trenner_Zeile_Linux=""+(char) 10;
//	public static final String trenner_Zeile_Win=  ""+(char) 13 + (char) 10;
//	public static final String trenner_Zeile_Mac=  """+(char) 13;
//	public static final char trenner_Verz_Linux=	'/';
//	public static final char trenner_Verz_Windows=	'\\';
//	public static final char trenner_Verz_Mac=		'/';


	private static String iZuKurzKlein(String name) {
		return FilterText.nicht(new char[]{' '}, name.toLowerCase());
	}
}
